package top.v5it.japi.plus.sdk;

import cn.hutool.core.net.URLDecoder;
import cn.hutool.core.util.EscapeUtil;
import cn.hutool.core.util.NumberUtil;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.math.BigDecimal;
import java.nio.charset.Charset;

/**
 * @author zhanpu
 * @date 2022/8/19
 */
@Setter
@Getter
public class StockInfo implements Serializable {
    private static final long serialVersionUID = -8065452509417300111L;

    /**
     * 股票名称
     */
    private String name;
    /**
     * 昨日收盘价
     */
    private Double yestclose;
    /**
     * 买5数量
     */
    private Long bidvol5;
    /**
     * 买4数量
     */
    private Long bidvol4;
    /**
     * 买3数量
     */
    private Long bidvol3;
    /**
     * 买2数量
     */
    private Long bidvol2;
    /**
     * 买1数量
     */
    private Long bidvol1;
    private Double bid5;
    private Double bid4;
    private Double bid3;
    private Double bid2;
    private Double bid1;
    private Long askvol5;
    private Long askvol4;
    private Long askvol3;
    private Long askvol2;
    private Long askvol1;
    private Double ask5;
    private Double ask4;
    private Double ask3;
    private Double ask2;
    private Double ask1;
    private String symbol;
    private Long volume;
    private Double price;
    private Double open;
    private Double low;
    private Double high;
    private String code;
    private Long turnover;
    private Double percent;
    private Double updown;
    private String update;
    private String type;
    private String time;
    private String arrow;

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        BigDecimal reta = NumberUtil.toBigDecimal(percent).movePointRight(2);
        reta = NumberUtil.div(reta, 1, 2);
        final String escape = EscapeUtil.unescape(arrow);
        final String decode = URLDecoder.decode(name, Charset.defaultCharset());
        sb
                .append(decode)
                .append("(")
                .append(code)
                .append(")")
                .append(escape)
                .append("\n")
                .append("当前价格：")
                .append(price)
                .append("\t")
                .append(reta)
                .append("%")
                .append("\n")
                .append("高：")
                .append(high)
                .append("\t")
                .append("开：")
                .append(open)
                .append("\t")
                .append("成交量：")
                .append(volume)
                .append("\n")
                .append("低：")
                .append(low)
                .append("\t")
                .append("昨日收盘价")
                .append(yestclose)
                .append("\t")
                .append("成交额：")
                .append(turnover)
                .append("\n")
                .append("卖价格\t卖数量")
                .append("\n")
                .append(NumberUtil.roundStr(ask5, 2))
                .append("\t")
                .append(askvol5)
                .append("\n")
                .append(NumberUtil.roundStr(ask4, 2))
                .append("\t")
                .append(askvol4)
                .append("\n")
                .append(NumberUtil.roundStr(ask3, 2))
                .append("\t")
                .append(askvol3)
                .append("\n")
                .append(NumberUtil.roundStr(ask2, 2))
                .append("\t")
                .append(askvol2)
                .append("\n")
                .append(NumberUtil.roundStr(ask1, 2))
                .append("\t")
                .append(askvol1)
                .append("\n")
                .append("买价格\t买数量")
                .append("\n")
                .append(NumberUtil.roundStr(bid1, 2))
                .append("\t")
                .append(bidvol1)
                .append("\n")
                .append(NumberUtil.roundStr(bid2, 2))
                .append("\t")
                .append(bidvol2)
                .append("\n")
                .append(NumberUtil.roundStr(bid3, 2))
                .append("\t")
                .append(bidvol3)
                .append("\n")
                .append(NumberUtil.roundStr(bid4, 2))
                .append("\t")
                .append(bidvol4)
                .append("\n")
                .append(NumberUtil.roundStr(bid5, 2))
                .append("\t")
                .append(bidvol5);
        return sb.toString();
    }
}
